<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6.并集-交集-差集算法实现</title>
</head>
<body>
  <script>
    let a = new Set([1,2,3,4,5]);
    let b = new Set([4,5,2,9]);
    //将两个集合合并成一个新的集合，由于Set特性当然也不会产生重复元素。
    let newSet =  new Set([...a,...b])
    console.log(newSet); //Set(6) {1, 2, 3, 4, 5, 9}
    // 差集，a中存在，b中不存在的
    newSet =  new Set([...a].filter(item=> 
    !b.has(item)
    ));
    console.log(newSet);//Set(2) {1, 3}

  </script>
</body>
</html>